#!/bin/bash
# Move a module using darcs and rpl, creating a shell script
if [ -e script.sh ]; then
  echo "remove script.sh first"; exit 1
fi
SRC=$1
TARGET=$2
shift 2
echo "darcs mv $SRC.hs $TARGET.hs || (echo darcs failed; exit 1)"             > script.sh
echo "darcs record ." >> script.sh
for path in $@; do
  if [ -d $path ]; then
      echo "(cd $path; rpl -x .hs -R ${SRC//\//.} ${TARGET//\//.} *; darcs amend .)" >> script.sh
  elif [ -e $path ]; then
      echo "(rpl ${SRC//\//.} ${TARGET//\//.} $path; darcs amend $path)" >> script.sh
  else
      echo "Non existing source file path $path"
      rm script.sh
      exit 1
  fi
done

